let Koa=require("koa");
let router=require("koa-router")();
let static=require("koa-static");
let views=require("koa-views");
let nunjucks=require("nunjucks");
let parser=require("koa-parser");
let session=require("koa-session");
let app=new Koa();
app.use(static(__dirname+"/public/pc端"));
app.use(views(__dirname+"/public/pc端",{
    map:{html:"nunjucks"}
}))
app.keys=["1231230"];
app.use(parser())
app.use(session({
    maxAge:1000*100
},app))
app.listen(3000);
router.get("/",async ctx=>{
    // ctx.session.username=""
    if(ctx.session.username){
        await ctx.render("首页",{
            // hide:"none",
            // show:"block",
            hide:"block",
            show:"none",
        })
        console.log(121)
    }else{
        await ctx.render("首页",{
            // hide:"block",
            // show:"none",
            hide:"none",
            show:"block"
        })
        // ctx.session.username=""
        console.log(222)
    }
})
router.get("/video",async ctx=>{
    if(ctx.session.username){
        await ctx.render("视频",{
            hide:"block",
            show:"none",
            hidee:"none",
            showw:"block",
            vip:"你以是vip",
            url:"blob:http://www.xiaozhoubg.com/74dc47d0-2d4a-4720-82b4-a8e7b41b77c2"
        })
        console.log(121)
    }else{
        await ctx.render("视频",{
            hide:"none",
            show:"block",
            hidee:"block",
            showw:"none",
            vip:"开通VIP观看"
        })
        console.log(222)
    }
})
router.get("/for",async ctx=>{
    await ctx.render("form")
})
router.post("/form", async ctx => {
    let username = ctx.request.body.text;
    let password = ctx.request.body.pass;
    console.log(username,password)
    if(username == "admin" && password == "123147"){
        ctx.session.username = "yi";
        ctx.redirect("/")
    }else{
        await ctx.render("form",{
            title:"用户名或密码错误"
        })
    }
})
app.use(router.routes())
